#define _CRT_SECURE_NO_WARNINGS
#include<string>
#include<stack>
#include<iostream>
#include<stdbool.h>
using namespace std;
class Solution {
public:
    bool isValid(string s) {
        stack<char> tmp;
        for (auto& ch : s)
        {
            if (ch == '(' || ch == '{' || ch == '[')
            {
                tmp.push(ch);
            }
            else
            {
                if (tmp.empty())
                {
                    return false;
                }
                char getChar = tmp.top();
                tmp.pop();
                if (ch == '}' && getChar != '{' || ch == ')' && getChar != '(' || ch == ']' && getChar != '[')
                {
                    return false;
                }
            }
        }
        if (!tmp.empty())
        {
            return false;
        }
        return true;
    }
};
int main()
{
    string s("{}()[]");
    cout << Solution().isValid(s) << endl;
    return 0;
}